package Eyjafjalla.action;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.DrawCardAction;
import com.megacrit.cardcrawl.actions.common.GainBlockAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.powers.watcher.VigorPower;

import java.util.ArrayList;

public class FireOfLoveAction extends AbstractGameAction {
    public FireOfLoveAction(boolean isFire,int blockMul,ArrayList<AbstractCard> discards){
        this.discards = discards;
        this.isFire = isFire;
        this.amount = blockMul;
        actionType = ActionType.DISCARD;
    }

    @Override
    public void update() {
        AbstractPlayer p = AbstractDungeon.player;
        if(discards==null)
        {
            this.isDone =true;
            return;
        }

        if(FastDrawCardAction.drawnCards.size()==0||discards.contains(FastDrawCardAction.drawnCards.get(0))){
            if(discards.size()>0){
                if(isFire){
                    addToTop(new ApplyPowerAction(p,p,new VigorPower(p,discards.size()),discards.size()));
                }
                addToTop(new GainBlockAction(p,discards.size()*this.amount));
            }
            this.isDone = true;
            return;
        }

        if(p.hand.size()>0){
            AbstractCard c = p.hand.getBottomCard();
            p.hand.moveToDiscardPile(c);
            c.triggerOnManualDiscard();
            AbstractDungeon.player.hand.applyPowers();
            discards.add(c);
        }

        addToTop(new FastDrawCardAction(1,new FireOfLoveAction(this.isFire,this.amount,this.discards),true));

        this.isDone = true;
    }

    ArrayList<AbstractCard> discards;
    boolean isFire;
}
